const Router = require('koa-router');
const router = new Router();
const {db } = require("../../models/db");

// 保存页面设置
router.post('/sets/saveParams', async ctx => {
    try {
        let id = ctx.request.body.id;
        let tenantId = ctx.user.tenantId;
        let data = JSON.stringify(ctx.request.body.data)
        if(id) {
            await db.models['options'].update({
                value: data
            },{
                where: {
                    id
                }
            })
            return ctx.suc('保存成功', id);
        }
        else {
            let model =  db.models['options'].build()
            model.tenantId = tenantId
            model.name = 'system'
            model.value = data
            await model.save()
            return ctx.suc('保存成功', model.id);
        }
    } catch (e) {
        return ctx.err(e);
    }
})






module.exports = router;